﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.Model;
using Hangjing.SQLServerDAL;
using Hangjing.Common;

namespace Html5
{
    public partial class shopsum : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserHelp.IsLogin_Togo(Request.Url.PathAndQuery);
            int pagesize = 8;
            int pageindex = HjNetHelper.GetQueryInt("PageNo", 1);

            PointsInfo user = UserHelp.GetUser_Togo();
            string sql = " 1=1 and OrderStatus = 3 and  Custorder.delflag= 0 and  togoid=" + user.Unid;
           

            string url = "shopsum.aspx?a=1";
            string starttime = WebUtility.InputText(Request["starttime"]);//开始日期
            string endtime = WebUtility.InputText(Request["endtime"]);//结束日期

            if (starttime != "")
            {
                sql += " and OrderDateTime > '" + starttime + "' ";
                url += "&starttime=" + starttime;


                tbstarttime.Value = starttime;

            }
            if (endtime != "")
            {
                sql  += " and OrderDateTime <  '" + endtime + " 23:59:59'";
                url += "&endtime=" + endtime;
                tbendtime.Value = endtime;
            }
            if (starttime == "" && endtime == "")
            {
                sql += " and DATEDIFF(day,OrderDateTime,GETDATE()) = 0 ";
                tbstarttime.Value = DateTime.Now.ToString("yyyy-MM-dd");
                tbendtime.Value = DateTime.Now.ToString("yyyy-MM-dd");
            }


            Custorder dalorder = new Custorder();

            CustorderInfo count = dalorder.GetCountAndTotal1(sql);
            CustorderInfo nopaycount = dalorder.GetCountAndTotal1(sql + " and Commentstate=0");

            //count.cardpay = nopaycount.OrderTotal + +nopaycount.delivergivemoney + nopaycount.OldPrice+ nopaycount.Commission;

            count.cardpay = nopaycount.shopdiscountmoney - nopaycount.Advance;

            IList<CustorderInfo> sumlist = new List<CustorderInfo>();
            sumlist.Add(count);

            WebUtility.BindRepeater(rptsum, sumlist);

            IList<CustorderInfo> orderlist = dalorder.GetList(pagesize, pageindex, sql, "Unid", 1);
            //添加支付状态 2015-11-24 
            foreach (var item in orderlist)
            {

            }

            WebUtility.BindRepeater(rptorder, orderlist);

            int countNum = new Custorder().GetCount(sql);
            int pagecount = 0;

            if (countNum % pagesize == 0)
            {
                pagecount = countNum / pagesize;
            }
            else
            {
                pagecount = countNum / pagesize + 1;
            }

            if (pagecount <= 1)
            {
                pages.Style["display"] = "none";
            }
            else
            {
                pages.InnerHtml = WebUtility.GetPageString(pageindex, pagecount, url);
            }
        }
    }
}
